/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.jf.cloud.user.controller.multishop;

import com.jf.cloud.user.model.UserTravels;
import com.jf.cloud.user.service.UserTravelsService;
import com.jf.cloud.user.vo.UserTravelsVO;
import com.jf.cloud.user.dto.UserTravelsDTO;

import com.jf.cloud.api.auth.bo.UserInfoInTokenBO;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * 
 *
 * @author zz
 * @date 2023-11-09 09:50:04
 */
@RestController("multishopUserTravelsController")
@RequestMapping("/m/user_travels")
@Tag(name = "")
public class UserTravelsController {

    @Autowired
    private UserTravelsService userTravelsService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取列表", description = "分页获取列表")
    public ServerResponseEntity<PageVO<UserTravels>> page(@Valid PageDTO pageDTO) {
        PageVO<UserTravels> userTravelsPage = userTravelsService.page(pageDTO);
        return ServerResponseEntity.success(userTravelsPage);
    }

    @GetMapping
    @Operation(summary = "获取", description = "根据id获取")
    public ServerResponseEntity<UserTravels> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(userTravelsService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存", description = "保存")
    public ServerResponseEntity<Void> save(@Valid @RequestBody UserTravelsDTO userTravelsDTO) {
        UserTravels userTravels = mapperFacade.map(userTravelsDTO, UserTravels.class);
        userTravels.setId(null);
        userTravelsService.save(userTravels);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新", description = "更新")
    public ServerResponseEntity<Void> update(@Valid @RequestBody UserTravelsDTO userTravelsDTO) {
        UserTravels userTravels = mapperFacade.map(userTravelsDTO, UserTravels.class);
        userTravelsService.update(userTravels);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除", description = "根据id删除")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        userTravelsService.deleteById(id);
        return ServerResponseEntity.success();
    }
}
